package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 利用类型
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum UseOrderTypeEnum {

  /** 电子利用 */
  ELECTRONIC_USE(1, "电子利用"),
  LOAN_IN_KIND(2, "实物外借"),
  ON_SITE_BORROWING(3, "现场借阅"),
  COPY_OUT(4, "复制外发"),
  USE_APPLY(5, "协查申请"),
  ARCH_PUSH(6, "主动推送"),
  ;

  private Integer code;
  private String desc;

  public static UseOrderTypeEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到利用类型：" + type));
  }

  @JsonCreator
  public static UseOrderTypeEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
